﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Reflection;
using System.Xml.Linq;
using System.IO;

namespace 玩具商城管理系统.znew
{
    public partial class Ninformation : Form
    {
        public Ninformation()
        {
            InitializeComponent();
        }
        public static string path_source = "";
        private void Nshopcar_Load(object sender, EventArgs e)
        {
            DB.GetCn();
            string str = "select *from client where client_name='" + login.username + "'";
            DataTable dt = DB.GetDataSet(str);
            txtname.Text = dt.Rows[0][0].ToString();
            cbsex.Text = dt.Rows[0][1].ToString();
            txtipone.Text = dt.Rows[0][2].ToString();
           
            DateTime defaultValue = DateTime.Now;
            if (dt.Rows[0][3] != DBNull.Value)
            {
                dateTimePicker1.Value = Convert.ToDateTime(dt.Rows[0][3]);
            }
            else
            {
                // 如果为空，将默认值赋给 dateTimePicker1.Value
                dateTimePicker1.Value = defaultValue;
            }
            txtarr.Text = dt.Rows[0][4].ToString();
            txtemail.Text = dt.Rows[0][7].ToString();
            textBox1.Text = dt.Rows[0][5].ToString();
            try
            {
                pictureBox1.Image = Image.FromFile(Application.StartupPath + dt.Rows[0][10].ToString());
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            }
            catch
            {
                pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\" + "人1.jpg");
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            }
        }

        private void btnok_Click(object sender, EventArgs e)
        {
            DB.GetCn();
            string sdr = "";
            string filename;
            string fileFolder;
            string dateTime = "";
            filename = Path.GetFileName(path_source);
            dateTime += DateTime.Now.Year.ToString();
            dateTime += DateTime.Now.Month.ToString();
            dateTime += DateTime.Now.Day.ToString();
            dateTime += DateTime.Now.Hour.ToString();
            dateTime += DateTime.Now.Minute.ToString();
            dateTime += DateTime.Now.Second.ToString();
            filename = dateTime + filename;
            fileFolder = Directory.GetCurrentDirectory() + "\\" + "Prod_Images\\" + "头像"
                + "\\";
            fileFolder += filename;
            if (path_source != "")
            {
                File.Copy(path_source, fileFolder, true);
                sdr = "\\Prod_Images\\" + "头像" + "\\"
               + filename;
            }
            string str = "update client set client_name='"
                + txtname.Text + "',client_sex='"
                + cbsex.Text + "',client_home='"
                + txtarr.Text + "',client_bith='"
                + dateTimePicker1.Value + "',client_ipone='"
                + txtipone.Text + "',client_email='" + txtemail.Text +"',client_ptho='"+sdr+ "'  where client_id='"
                + Convert.ToInt32(textBox1.Text) + "'";

            DB.sqlEx(str);

            MessageBox.Show("修改成功");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                path_source = ofd.FileName;
                pictureBox1.Image = Image.FromFile(path_source);
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            }
        }
    }
}
